package org.itboys.core.service.mysql.front;

import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.core.common.SundayCommonConstants;
import org.itboys.core.dao.tray.SundayTrayMapper;
import org.itboys.core.entity.mysql.tray.SundayTray;
import org.itboys.framework.resource.ResourceHolder;
import org.itboys.mysql.service.BaseMySqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者：zzq
 * 时间：2018/12/19
 * 描述：
 */
@Service
public class SundayFrontTrayService extends BaseMySqlService<SundayTray> {
    @Autowired
    private SundayTrayMapper trayMapper;
    @Autowired
    private ResourceHolder resourceHolder;

    public Map<String, Object> countTime(Long ownerId) {
        Map<String, Object> result = new HashMap<String, Object>();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("ownerId", ownerId);
        param.put("time", 300);
        Long newNum = Long.valueOf(trayMapper.countTime(param).toString());
        param.clear();
        param.put("ownerId", ownerId);
        param.put("time", 600);
        Long simpleNum = Long.valueOf(trayMapper.countTime(param).toString());
        param.clear();
        param.put("ownerId", ownerId);
        param.put("status", SundayCommonConstants.tray_status_ysh);
        Long harmNum = super.count(param);
        param.clear();
        param.put("ownerId", ownerId);
        Long totalNum = super.count(param);
        result.put("newNum", newNum);
        result.put("simpleNum", simpleNum);
        result.put("harmNum", harmNum);
        result.put("totalNum", totalNum);
        return result;
    }


    public Map<String, Object> selectByModel(Long ownerId) {
        Map<String, Object> result = new HashMap<String, Object>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<Integer> statues = new ArrayList<>();
        statues.add(1);
        statues.add(2);
        param.put("ownerId", ownerId);
        param.put("statues", statues);
        Long ableNum = Long.valueOf(trayMapper.count(param).toString());
        param.clear();
        param.put("ownerId", ownerId);
        Long upNum = Long.valueOf(trayMapper.count(param).toString());
        param.clear();
        param.put("ownerId", ownerId);
        List<Map<String, Object>> trays = trayMapper.selectByModel(param);
        if (ListUtil.isNotNull(trays)) {
            for (Map<String, Object> map : trays) {
                param.clear();
                param.put("serviceId", ownerId);
                param.put("modelId", map.get("modelId"));
                param.put("status", SundayCommonConstants.tray_status_dzl);

                Long storeNum = Long.valueOf(trayMapper.count(param).toString());
                map.put("storeNum", storeNum);
                map.put("image", resourceHolder.getStringValue("imgRoot") + map.get("image"));
            }
        }
        result.put("trays", trays);
        result.put("ableNum", ableNum);
        result.put("upNum", upNum);
        return result;
    }
}
